#include <iostream>
using namespace std;

const int N=5e5+10;
int a[N][30], p[N], e[N];
int n, m, idex;


void insert(string& s)
{
	int cur=0;
	p[cur]++;
	
	for(auto& ch: s)
	{
		int path=ch-'a';
		if(a[cur][path]==0) a[cur][path]=++idex;
		cur=a[cur][path];
		p[cur]++;
	}
	e[cur]++;
}

void flag(string& s)
{
	int cur=0;
	
	for(auto& ch: s)
	{
		int path=ch-'a';
		if(a[cur][path]==0)
		{
			cout<<"WRONG"<<endl;
			return ;
		}
		
		cur=a[cur][path];
	}
	if(e[cur]==0)
	{
		cout<<"WRONG"<<endl;
	}
	else if(e[cur]==-1)
	{
		cout<<"REPEAT"<<endl;
	}
	else
	{
		cout<<"OK"<<endl;
		e[cur]=-1;
	}

}


int main()
{
	cin>>n;
	while(n--)
	{
		string s; cin>>s;
		insert(s);
	}
	cin>>m;
	while(m--)
	{
		string s; cin>>s;
		flag(s); 
	}
	return 0;
}
